// pages/person/suggestion/suggestion.js
var req = require("../../utils/action.js");
var utils = require("../../utils/util.js");
var _tools = require("../../utils/myTools.js");
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    message:"",
    phone:"",
    customerId:"",
    btnDisabled:false
  },

  onLoad: async function (options) {
    let userInfo = await getApp().globalData.userInfo 
    this.setData({customerId:userInfo.id})
  },
  onTextareaChange:function(e){
    this.setData({message:e.detail.value})
  },
  onContactChange:function(e){
    this.setData({phone:e.detail.value})
  },
  handleSubmit:function(){
    if(this.validate()){
      let r = {customer_id:this.data.customerId,message:this.data.message,phone:this.data.phone}
      let _url = req.actions.ym+"suggestion/addSuggestion";
      let that = this;
      that.setData({btnDisabled:true})
      utils.myResquest(r,_url,function(res){
        if(res.data.code == '200'){
          wx.showToast({title: '意见提交成功',icon: "success",duration: 2e3})
          setTimeout(function(){
            wx.navigateBack({
              delta: -1,
            })
          },2000)
          
        }else{
          wx.showToast({title: '意见提交失败',icon: "fail",duration: 2e3})
        }
        that.setData({btnDisabled:false})
      });
    }
  },
  validate:function(){
    var e=this.data, t = e.message, n = e.phone;
    return t ? !(n && !(0, _tools.isChineseMobilePhoneNumber)(n) && !(0, _tools.isEmail)(n)) || (wx.showToast({
        title: "联系方式输入格式错误",
        icon: "none"
    }), !1) : (wx.showToast({
        title: "问题描述不能为空",
        icon: "none"
    }), !1);
  },
  onReady: function () {},
  onShow: function () {},
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},
  onReachBottom: function () {},
  onShareAppMessage: function () {}
})